import bisect
class Solution(object):
    def longestObstacleCourseAtEachPosition(self, obstacles):
        DP = []
        ans = []
        for num in obstacles:
            index = bisect.bisect_right(DP, num)
            ans.append(index + 1)
            if index == len(DP):
                DP.append(num)
            else:
                DP[index] = num
        return ans
                
data = Solution()
obstacles = [1,2,3,2]
print(data.longestObstacleCourseAtEachPosition(obstacles))